package com.hu.bgp.client.widgets.uicomponents;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.FlexTable;

public class HeaderedFlexTable extends FlexTable
{
	private Element head;
	private Element headerTr;

	public HeaderedFlexTable()
	{
		super();
		head = DOM.createTHead();
		headerTr = DOM.createTR();
		DOM.insertChild(getElement(), head, 0);
		DOM.insertChild(head, headerTr, 0);
	}

	public void setHeaderElement(int column, Element element)
	{
		// wrap element in a TH
		Element th = DOM.createTH();
		DOM.insertChild(th, element, 0);
		// overwrite old position if we're not inserting at the end
		if (DOM.getChildCount(headerTr) > column)
		{
			DOM.removeChild(headerTr, DOM.getChild(headerTr, column));
		}
		DOM.insertChild(headerTr, th, column);
	}
}